function [nodesc, edgesc] = export_ggraph(matrix,nodeLabels,nodeAtr)
%EXPORT_GGRAPH	export graph to csv format
%	[nodes, edges] = export_ggraph(matrix, nodeLabels) 
%	
%
%	Inputs:     matrix          matrix with weights and connection between
%                               nodes
%               nodeLabels      IDs of the nodes
%		
%		
%	Outputs:    nodes           nodes table ID
%               edges           edges table
%		
%	
%	See also cell2csv

%	References: https://gephi.org/users/supported-graph-formats/spreadsheet/
%	
%	

%	Copyright 2013 MAF Pimentel
%	This program is free software: you can redistribute it and/or modify
%	it under the terms of the GNU General Public License as published by
%	the Free Software Foundation, either version 3 of the License, or
%	(at your option) any later version.
%	
%	This program is distributed in the hope that it will be useful,
%	but WITHOUT ANY WARRANTY; without even the implied warranty of
%	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%	GNU General Public License for more details.
%	
%	You should have received a copy of the GNU General Public License
%	along with this program.  If not, see <http://www.gnu.org/licenses/>.


%	$Author: MAF Pimentel$
%	$Revision: 1.0.0.0$
%	$Date: 14-Jun-2013 14:26:17$
%	Contact: marco.and.pimentel@gmail.com
%	Originally written on: PCWIN64

if nargin < 1
    nodeLabels = {'A','B','C'};
    matrix =   [1 0 1; ...
                0 1 .5; ...
                1 .5 1];
    nodeAtr = {'1','0','1'};
end

nodesc = cell(length(nodeLabels)+1,1+size(nodeAtr,1));
nodesc{1} = 'Id';
for j = 1 : size(nodeAtr,1)
    nodesc{1,j+1} = sprintf('Atr_%d',j);
end
for i = 1 : length(nodeLabels)
    nodesc{i+1,1} = nodeLabels{i};
    for j = 1 : size(nodeAtr,1)
        nodesc{i+1,j+1} = nodeAtr{j,i};
    end
end

N = size(matrix,1);
edgesc = cell(1 + N*(N-1),4); n = 2;
edgesc{1,1} = 'Source'; edgesc{1,2} = 'Target'; 
edgesc{1,3} = 'Type'; edgesc{1,4} = 'Weight';
for i = 1 : N
    for j = 1 : N
        if i ~= j
            edgesc{n,1} = nodeLabels{i}; edgesc{n,2} = nodeLabels{j};
            edgesc{n,3} = 'Undirected'; edgesc{n,4} = matrix(i,j);
            n = n + 1;
        end
    end
end

cell2csv('edges_file.csv',edgesc);
cell2csv('nodes_file.csv',nodesc);

end